package com.huang.common.utils;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * @author hqy
 * @date 2022年06月21日 16:24
 */
public class SecurityAuthenticationUtils {

    /**
     * 获取上下文对象中的用户id
     * @return
     */
    public static Long getUserId(){
        String principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString();
        return Long.valueOf(principal);
    }


    public static Authentication getAuthentication(){
        return SecurityContextHolder.getContext().getAuthentication();
    }
}
